/**
 * Плагин загрузки шаблонов
 * @author Vladimir Mozolev (mutantdd@yandex.ru)
 */
(function($){
    var options = {
        templatePath: null,
        fileExt: "html",
        errorContent: "Page not available"
    };

    var templateCache = [];

    $.getTemplate = function(id){
        if (options.templatePath) {
            if (templateCache[id]) {
                return templateCache[id];
            }
            var templateContent = options.errorContent;
            $.ajax({
                type: "GET",
                url: (options.templatePath + "/" + id + "." + options.fileExt).replace(/\/{2,}/g,'/'),
                dataType: "HTML",
                async: false,
                ifModified: false,
                success: function(data){
                    templateContent = data;
                    templateCache[id] = templateContent;
                }
            });
            return templateContent;
        }
        return "Error: template path not set";
    };

    $.getTemplate.options = function(inOptions) {
        $.extend(options, inOptions);
    };
})(jQuery);